package com.csd.controller;

import com.csd.dto.ActionResult;
import com.csd.po.Car;
import com.csd.po.City;
import com.csd.service.CarService;
import com.csd.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 车辆信息控制层（接口）
 *
 * @author junlong
 * @date 2020/12/22 23:29
 */
@Controller
@RequestMapping("/car")
public class CarController {
    @Autowired
    private CarService carService;

    /**
     * 按照租金排序
     * @param cid
     * @return
     */
    @RequestMapping("/findCarByCid")
    @ResponseBody
    public ActionResult findCar(Integer cid) {
        List<Car> cars = carService.findCarByCid(cid);

        for (Car car:cars){
            System.out.println(car);
        }
        System.out.println("-------------------------------------------");
        return new ActionResult(200, "success", cars);
    }

    /**
     * 按照热度排序
     * @param cid
     * @return
     */
    @RequestMapping("/findCarByNumber")
    @ResponseBody
    public ActionResult findCarByNumber(Integer cid){

        List<Car> carByNumber = carService.findCarByNumber(cid);

        for (Car car:carByNumber) {
            System.out.println(car);
        }
        return new ActionResult(200,null,carByNumber);
    }
    /**
     * 根据id查询车
     */
    @RequestMapping("/findCarById")
    @ResponseBody
    public ActionResult findCarById(int id){
       Car car= carService.findCarByIid(id);
        System.out.println(car);
       return new ActionResult(200,null,car);
    }
}
